import { useUserStore } from './../store/modules/user';
import axios from 'axios'

const instance = axios.create({
  baseURL: 'http://localhost:3000',
  timeout: 5000
})

// 请求拦截器
instance.interceptors.request.use(config => {
  const { token } = useUserStore()
  if (token){
    // 用户已经登录
    config.headers.common['Authorization'] = token
  }
  return config
}, err => {
  return Promise.reject(err)
})



export default instance